import { nanoid } from 'nanoid'
import React, { Component } from 'react'

export default class header extends Component {
    handleAddTodo = (event) => {
        //获取键盘码，input值
        const {keyCode,target} = event
        if(keyCode != 13) return
        if(target.value.trim()=='') return alert('不能为空！')
        const todo ={
            id: nanoid(),
            name: target.value.trim(),
            done: false
        }
        console.log(todo)
        this.props.AppAddTodo(todo)
    }
    render() {
        return (
            <div className="todo-header">
                <input onKeyUp={this.handleAddTodo} type="text" placeholder="请输入你的任务名称，按回车键确认" />
            </div>
        )
    }
}
